<template>
	<view  class="submit" :style="{bottom:keyboardHeight+'px'}">
		<view class="submit-chat">
			<!-- 文本框 -->
			<textarea :adjust-position="false"  auto-height="true" class="chat-send btn" @input="inputs"
				cursor-spacing='60rpx' v-model="msg" @focus="focus"></textarea>

			<view class="sendBtn" @tap="sendBtn">
				发送
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			safeBottom:0,
			dialogCount: 0,
			keyboardHeight: 0,
		},
		data() {
			return {
				msg: "",
				// 直接引用地址可能出不来，需要用require
				bottom: 0,
			};
		},
		
		methods: {
			mousemove() {
				console.log(11);
				uni.hideKeyboard()
			},
			sendBtn() {
				console.log(uni.$u.trim(this.msg, 'all'))
				if (!uni.$u.trim(this.msg, 'all')) return
				this.send(this.msg, 1)
			},
			//文字发送
			inputs(e) {
				var chatm = e.detail.value;
				var pos = chatm.indexOf('\n');
				// 检索字符串没有数据，返回-1
				// if (pos != -1 && chatm.length > 1) {
				// this.$emit('inputs', this.msg);
				// setTimeout(() => {
				// 	this.msg = '';
				// }, 0)
				// }
				if (!uni.$u.trim(this.msg, 'all')) return
				if (pos != -1 && chatm.length > 1) {
					// 0为表情和文字
					this.send(this.msg, 0)
				}

			},
			focus(e){
				console.log(e)
			},
			//发送
			send(msg, type) {
				let date = {
					message: msg,
					type: type
				}
				if (!this.isVip()) {
					if (uni.getStorageSync('config')['client.limited.exemption.enable']) {
						if (this.dialogCount > 2) {
							uni.showToast({
								title: '3次免费体验已用尽',
								icon: 'none'
							})
							setTimeout(() => {
								uni.redirectTo({
									url: '/packageA/pages/vipCenter/vipCenter'
								})
							}, 2000)
							return
						}
					} else {
						uni.redirectTo({
							url: '/packageA/pages/vipCenter/vipCenter'
						})
						return
					}
				}
				this.$emit('inputs', date);
				setTimeout(() => {
					this.msg = '';
				}, 0)
			}
		}
	};
</script>

<style lang="scss" scoped>
	.submit {
		background: #282A31;
		width: 100%;
		position: fixed;
		bottom: 0;
		z-index: 11100;
		color: #333;
	}

	.submit-chat {
		width: 100%;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		padding: 40rpx 32rpx;

		image {
			width: 56rpx;
			height: 56rpx;
			margin: 0 10rpx;
			flex: auto;
		}

		.btn {
			flex: auto;
			color: #fff;
			border-radius: 10rpx;
			padding: 20rpx;
			max-height: 160rpx;
			margin: 0 10rpx;
			width: 572rpx;
			border-radius: 52rpx 52rpx 52rpx 52rpx;
			border: 2rpx solid #47E969;
		}

		.chat-send {
			line-height: 44rpx;
		}

		.record {
			line-height: 44rpx;
			text-align: center;
			font-size: 20rpx;
		}

		.sendBtn {
			color: #fff;
			width: 120rpx;
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			font-size: 28rpx;
			background: linear-gradient(98deg, #4EBC7B 0%, #47E969 100%);
			box-shadow: 0rpx 8rpx 24rpx 0rpx rgba(75, 211, 114, 0.3);
			border-radius: 10rpx;
		}
	}
</style>